﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Domain.DataEntity;

namespace TjZheng.Editor
{
    public class UploadConfig
    {
        public UploadConfig()
        {

        }
        public UploadConfig(UploadLimit objUploadLimit)
        {
            this.UploadLimit = objUploadLimit;
            if (objUploadLimit.LimitExtension.Contains("*.*"))
            {
                this.AllowExtensions = new string[] { "*.*" };
            }
            else
            {
                this.AllowExtensions = objUploadLimit.LimitExtension.Trim(';').Trim().Replace("*", "").Replace(" ", "").Split(';');
            }

            //this.PathFormat = string.Format("/FileSource/{0}/{1}/{2}/{{time}}{{rand:6}}", objUploadLimit.UcCode, objUploadLimit.LimitCode, DateTime.Now.ToString("yyyyMMdd"));
            this.SizeLimit = objUploadLimit.LimitSize == 0 ? int.MaxValue : objUploadLimit.LimitSize * 1024;
            this.ServerPath = objUploadLimit.ServerPath;
        }
        /// <summary>
        /// 文件命名规则
        /// </summary>
        public string PathFormat { get; set; }

        /// <summary>
        /// 上传表单域名称
        /// </summary>
        public string UploadFieldName { get; set; }

        /// <summary>
        /// 上传大小限制
        /// </summary>
        public int SizeLimit { get; set; }

        /// <summary>
        /// 上传允许的文件格式
        /// </summary>
        public string[] AllowExtensions { get; set; }

        /// <summary>
        /// 文件是否以 Base64 的形式上传
        /// </summary>
        public bool Base64 { get; set; }

        /// <summary>
        /// Base64 字符串所表示的文件名
        /// </summary>
        public string Base64Filename { get; set; }

        /// <summary>
        /// 存储服务器
        /// </summary>
        public string ServerPath { get; set; }

        /// <summary>
        /// 上传资源限制
        /// </summary>
        public UploadLimit UploadLimit { get; set; }
    }
}
